package com.dataaccess.dataaccess.web.service;

import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import com.dataaccess.dataaccess.common.base.BaseService;
import com.dataaccess.dataaccess.support.model.RespEntity;
import com.dataaccess.dataaccess.support.utils.DateUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;


/**
 * @Author: YangYu
 * @ClassName: TemperatureAndHumidityService
 * @Date: Created in 09:19 2023/11/30
 * @Description: 温湿度
 */
@Service
public class TemperatureAndHumidityService extends BaseService {
    @Resource
    private AsyncService asyncService;
    /**
     * @Author YangYu
     * @Description 山东123物联（温湿度T2o）
     * @Date Created in 10:43 2021/11/24
     * @Param [jsonParam]
     */

    public RespEntity t20(JSONObject jsonParam) throws Exception {
        if (jsonParam.getStr("messageType").equals("dataReport")){
            //设备号
            String number = jsonParam.getStr("IMEI");
            //时间
            String time = DateUtils.contextLoads(jsonParam.getLong("timestamp"));
            //最终推送数据
            JSONObject jsonParamN = new JSONObject();
            jsonParamN.put("number", number);
            // 温度
            double temp = jsonParam.getJSONObject("payload").getDouble("TEMP")/10;
            // 湿度
            double humi = jsonParam.getJSONObject("payload").getDouble("HUMI")/10;
            //正常数据信息
            JSONArray jSONArray = new JSONArray();
            JSONObject tem = new JSONObject();
            tem.put("name", "温度");
            tem.put("value", temp);
            jSONArray.add(tem);
            JSONObject hum = new JSONObject();
            hum.put("name", "湿度");
            hum.put("value", humi);
            jSONArray.add(hum);
            //rest调用平时数据添加接口：
            jsonParamN.put("paraminfo", jSONArray);
            jsonParamN.put("time", time);
            fireFightingiot(jsonParamN, "firefightingiot_data", "normalInfo", "device");
            jsonParamN.put("state","1");
            //异步更新传输装置状态
            asyncService.updateDeviceCurrentState(jsonParamN);
        }
        //解析数据结束-------------------------------------------------------------------------------------------------------
        return RespEntity.success();
    }

}
